package com.didispace;

import java.util.concurrent.TimeUnit;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

	@RequestMapping(value="/hello", method = RequestMethod.GET)
    public String hello() {
        return "hello world";
    }
    
    @RequestMapping(value="/hello1", method = RequestMethod.GET)
    public String hello(@RequestParam String userName) {
    	try {
			TimeUnit.SECONDS.sleep(4);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return "hello" + userName;
    }
    
    @RequestMapping(value="/hello2", method = RequestMethod.GET)
    public User hello2(@RequestHeader String userName, @RequestHeader String id) {
    	return new User(userName, id);
    }
    
    
    @RequestMapping(value="/hello3", method = RequestMethod.POST)
    public String hello3(@RequestBody User user) {
    	return "hello" + user.getUserName() + "," + user.getId();
    }
}
